<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>animateMotion动画-复用路径</title>
    <style>
      body,
      ul {
        margin: 0;
        padding: 0;
      }

      body {
        background-image: url(../../images/grid.png);
      }
      svg {
        background-color: rgba(255, 0, 0, 0.1);
      }
    </style>
  </head>
  <body>
    <svg width="300" height="300" xmlns="http://www.w3.org/2000/svg">
      <!-- 画一条路径 -->
      <path
        id="linePath"
        d="M 0 100, L 100 30, L 200 100, L 300 30"
        fill="transparent"
        stroke="red"
      ></path>

      <rect x="0" y="0" width="20" height="10" rx="4" ry="4" fill="red">
        <animateMotion dur="5s" rotate="auto">
          <!-- 
            mpath元素用于引用路径，从而实现路径动画
            href属性用于指定路径的id
          -->
          <mpath href="#linePath"></mpath>
        </animateMotion>
      </rect>
    </svg>
  </body>
</html>
